1. Field of the Invention
The present invention relates to a method of tracing an object allocation site in a program, as well as a computer system and a computer program for tracing.
2. Description of Related Art
In many programs, numerous objects are dynamically allocated in the heap space of memory. There are multiple object allocation sites in the program, or more specifically, in source code or intermediate code such as bytecode. In the Java language for example, the object allocation site in the program is where the new operator for creating an object is described. The object described in the program is allocated in the heap space of memory at the time of program execution. If the object allocation site in source code or in intermediate code such as bytecode of the program can be detected from the object allocated in the heap space, debugging and optimization for various programs can be performed efficiently.
Assume, for example, that a memory leak is suspected at a certain point during program execution. If the allocation sites can be detected from all the live objects in the heap space, the site in the program in which many objects are allocated can be identified. Such identification allows a programmer to take a measure against the memory leak. Here, “a memory leak” is a phenomenon in which a usable memory space gradually decreases. A memory leak occurs when, for example, objects no longer needed remain and are accumulated in memory. “Live objects” are objects that are being referred to, with a pointer, by a program executing certain processing so as to be used in that processing.
There is a case, for example, where multiple threads frequently lock a certain object one after another. In this case, if the allocation site in the program of the certain object is identified, object lock reservations by other threads can be stopped so that a certain thread can lock the certain object. See K. Russell and D. Detlefs, Eliminating Synchronization-Related Atomic Operations with Biased Locking and Bulk Rebiasing. Proceedings of the ACM SIGPLAN 2006 Conference on Object-Oriented Programming, Systems, Languages, and Applications, pp. 263-272, 2006.
In one method to allow the object allocation site in the program to be identified, an object header is expanded, and an allocation site number having the size of one word is embedded in that expanded space. See R. Shaham, E. K. Kolodner, and M. Sagiv, Heap Profiling for Space-Efficient Java. Proceedings of the ACM SIGPLAN 2001 Conference on Programming Language Design and Implementation, pp. 104-113, 2001. However, since the method involves header expansion, more heap space is consumed. Moreover, use of the expansion header fundamentally changes how the heap space is used, and accordingly it becomes difficult to debug how the heap space is used.
Another conceivable method for allowing the object allocation site in the program to be identified is to prepare, outside the heap space, a correspondence table in which an object and its allocation site in the program are associated with each other on a one-on-one basis. With this method, however, the correspondence table increases in size in proportion to the number of objects. Consequently, more memory is consumed to store the correspondence table. Furthermore, this method requires processing of deleting, from the correspondence table, information on a dead object that is no longer being referred to by anything. Consequently, this method has a demerit that such deletion processing increases a program speed overhead.
In a program that involves allocation of many small-sized objects, e.g., a program created in the Java language, a run-time object in the heap space does not have information that indicates an object allocation site in the program.
There is an example in which information indicating the object allocation site in the program is added to the run-time object in the heap space. See R. Shaham, E. K. Kolodner, and M. Sagiv, Heap Profiling for Space-Efficient Java. Proceedings of the ACM SIGPLAN 2001 Conference on Programming Language Design and Implementation, pp. 104-113, 2001. In this example, however, extra space is consumed in the heap space. Accordingly, the existing methods still have a difficulty in allowing the object allocation site in the program to be efficiently traced from the run-time object in the heap space of memory without consuming much memory. Therefore, there is a demand for a method of efficiently tracing the object allocation site in the program.